package iSOCK::Controller::Specification::Abstract;

use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller' }

use iSOCK::Controller::Root;

=head1 NAME

iSOCK::Controller::Abstract - Abstract Controller for iSOCK

=head1 DESCRIPTION

[enter your description here]

=head1 METHODS

=cut

sub index :Path :Args(0) {
  my ( $self, $c ) = @_;
  
  my $session      = $c->session;
  my $session_id   = $c->sessionid;
  my $session_path = iSOCK::Controller::Root->session_path ( $c );
  
  if ( my $abstract_file = $session->{abstract_file} ) {
    if ( open my $fh, '<', "$session_path/$abstract_file" ) {
      my $body = join '', map {
        s/<a \b (.*) href="(\w+\.html\#\w+)" (.*) > (.+) <\/a>/<span class='non_applicable'>$4<\/span>/x;

        s/<object \b (.*) data="(.+)" (.*) >/<object${1}data="\/tmp\/$session_id\/5_HTML_out\/$2"${3}>/x;

        $_;
      } grep { m/\<div id="(header|navigation|menu|content|footer)"\>/ .. m/\<\/div\>/ } <$fh>;
      
      $c->stash ( body => $body );
      
      $c->detach ( qw( iSOCK::Controller::Root render_view ) );
    }
  }
  
  $c->response->redirect ( $c->uri_for ( '/specification/process' ) );
}

sub end : ActionClass('RenderView') {}

=head1 AUTHOR

Xavier Caron

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
